﻿using Anke.SHManage.BLL;
using Anke.SHManage.MSSQLDAL;
using Anke.SHManage.MSSQLDAL.TJDAL;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Anke.SHManage.Web.Reports
{
    public partial class TJ_CLCDFSModeWebForm : System.Web.UI.Page
    {
        private string reportName;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.ReportViewer1.LocalReport.EnableHyperlinks = true;
                InitPage();

            }
            else
            {
                reportName = Convert.ToString(ViewState["reportName"]);
            }

        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindReportDataSource();
        }

        private void InitPage()
        {
            this.StartDate.Text = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 07:30:00");
            this.EndDate.Text = DateTime.Now.ToString("yyyy-MM-dd 07:30:00");

            if (Request.QueryString["ReportName"] != null)
            {
                reportName = Request.QueryString["ReportName"];
                ViewState["reportName"] = reportName;
            }
            else
            {
                reportName = "LS_ZDTFXZHSG.rdlc";
                ViewState["reportName"] = reportName;
            }
            BindReportDataSource();
        }

        protected void BindReportDataSource()
        {

            DateTime start = Convert.ToDateTime(this.StartDate.Text);
            DateTime end = Convert.ToDateTime(this.EndDate.Text);
            //string center = (this.Center.Text).ToString();
            string station = (this.Station.Text).ToString();
            string start1 = start.ToString();
            string end1 = end.ToString();

            this.ReportViewer1.LocalReport.DataSources.Clear();
            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/" + reportName);
            Microsoft.Reporting.WebForms.ReportParameter st = new Microsoft.Reporting.WebForms.ReportParameter("StartTime", start1);
            Microsoft.Reporting.WebForms.ReportParameter ed = new Microsoft.Reporting.WebForms.ReportParameter("EndTime", end1);
            this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { st, ed });
            string eventDispatchCenterID = UserOperateContext.Current.Seesion_Dispatch_SubCenterID; //2020-11-22 zch 登录人所处急救中心
            TJDAL dal = new TJDAL();
            switch (reportName)
            {
                case "TJ_CLCDFS.rdlc"://车辆出动方式统计表 
                    this.Page.Title = "车辆出动方式统计表";
                    DataTable dt1 = dal.Get_TJ_CLCDFS(start, end,station,eventDispatchCenterID);//去掉了“center”
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_CLCDFS", dt1));
                    break;
                case "TJ_GPSAYBZC.rdlc"://GPS按压不正常流水表        
                    this.Page.Title = "GPS按压不正常流水表";
                    DataTable dt2 = dal.Get_TJ_GPSAYBZC(start,end,station,eventDispatchCenterID);//去掉了“center”
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_GPSAYBZC", dt2));
                    break;
                default: break;
            }
            this.ReportViewer1.LocalReport.Refresh();
        }
    }

}